<template>
    <div class="department">
        <div class="search">
            <el-form :inline="true" :model="searchData" size="mini" class="demo-form-inline">

                <el-form-item label="部门：">
                    <!-- <el-select v-model="searchData.u_d_id" placeholder="请选择部门"  @change="obtainUser">
                        <el-option-group v-for="group in optionName" :key="group.label" :label="group.label">
                            <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-option-group>
                    </el-select> -->
                    <el-select v-model="searchData.u_d_id" @change="obtainUser">
                        <!-- <el-option v-for="(item,index) in optionName" :key="index" :label="item.name" :value="item.id"></el-option> -->
                        <el-option-group v-for="group in optionName" :key="group.label" :label="group.label">
                            <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-option-group>
                    </el-select>
                </el-form-item>
                <el-form-item label="员工：">
                    <el-select v-model="searchData.u_id" placeholder="请选择员工" >
                        <el-option v-for="(item,index) in userType" :key="index" :label="item.u_username" :value="item.u_id"></el-option>
                    </el-select>
                </el-form-item>
                <!-- <el-form-item label="名称:">
                    <el-input v-model="searchData.u_username" placeholder="请输入名称"></el-input>
                </el-form-item>
                <el-form-item label="手机号:">
                    <el-input v-model="searchData.u_account_number" placeholder="请输入手机号"></el-input>
                </el-form-item> -->
                <el-form-item>
                    <el-button type="primary" @click="search">查询</el-button>
                    <el-button type="primary" @click="add">添加员工</el-button>
                </el-form-item>
            </el-form>
        </div>

        <div class='content'>
            
            <el-dialog :title="dialogtitle" :visible.sync="centerDialogVisible" v-if="centerDialogVisible" width="60%" center @close="dialogclose">
                <el-form :model="form" :rules="rules" ref="form" label-width="140px" class="demo-ruleForm" inline size="mini">
                    <el-form-item label="所属部门" prop="u_d_id">
                        <el-select v-model="form.u_d_id" placeholder="请选择所属部门">
                            <!-- <el-option v-for="(item,index) in optionName" :key="index" :label="item.name" :value="item.id"></el-option> -->
                            <el-option-group v-for="group in optionName" :key="group.label" :label="group.label">
                                <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-option-group>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="用户名称" prop="u_username">
                        <el-input v-model="form.u_username" placeholder="请输入用户名称"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="用户登陆账号" prop="u_account_number" v-if="dialogtitle === '添加员工'">
                        <el-input v-model="form.u_account_number" placeholder="请输入"></el-input>
                    </el-form-item> -->
                    <el-form-item label="密码" prop="u_password" v-if="dialogtitle === '添加员工'">
                        <el-input v-model="form.u_password" placeholder="请输入密码"></el-input>
                    </el-form-item>
                    <el-form-item label="账号状态" prop="u_status" v-if="dialogtitle === '修改员工信息'">
                        <el-select v-model="form.u_status" placeholder="请选择账号状态">
                            <el-option label="正常" value="1"></el-option>
                            <el-option label="禁用" value="2"></el-option>
                            <el-option label="离职" value="3"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="性别" prop="sex">
                        <el-select v-model="form.sex" placeholder="请选择性别"> 
                            <el-option label="男" value="1"></el-option>
                            <el-option label="女" value="2"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="员工生日" prop="birthday">
                        <el-date-picker type="date" placeholder="请选择" v-model="form.birthday" value-format="yyyy-MM-dd"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="籍贯" prop="jiguan">
                        <el-input v-model="form.jiguan" placeholder="请输入"></el-input>
                    </el-form-item>
                    <el-form-item label="民族" prop="nation">
                        <el-input v-model="form.nation" placeholder="请输入"></el-input>
                    </el-form-item>
                    <el-form-item label="毕业院校" prop="college">
                        <el-input v-model="form.college" placeholder="请输入"></el-input>
                    </el-form-item>
                    <el-form-item label="政治面貌" prop="political_face">
                        <el-input v-model="form.political_face" placeholder="请输入"></el-input>
                    </el-form-item>
                    <el-form-item label="所学专业" prop="speciality">
                        <el-input v-model="form.speciality" placeholder="请输入"></el-input>
                    </el-form-item> 
                    <el-form-item label="学历" prop="record_type">
                        <el-select v-model="form.record_type" placeholder="请选择">
                            <el-option v-for="(item,index) in recordType" :key="index" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="身份证号码" prop="people_num">
                        <el-input v-model="form.people_num" placeholder="请输入"></el-input>
                    </el-form-item>
                    <el-form-item label="联系电话" prop="phone">
                        <el-input v-model="form.phone" placeholder="请输入"></el-input>
                    </el-form-item>
                    <el-form-item label="电子邮箱" prop="email">
                        <el-input type="email" v-model="form.email" placeholder="请输入"></el-input>
                    </el-form-item>
                    <el-form-item label="现居住地" prop="address">
                        <el-input v-model="form.address" placeholder="请输入"></el-input>
                    </el-form-item>
                    <el-form-item label="银行卡号" prop="bank_num">
                        <el-input type="number" v-model="form.bank_num" placeholder="请输入银行卡号"></el-input>
                    </el-form-item>
                    <el-form-item label="银行名字" prop="bank_remark">
                        <el-input v-model="form.bank_remark" placeholder="请输入银行名字"></el-input>
                    </el-form-item>
                    <el-form-item label="个人简介" prop="personal_profile">
                        <el-input v-model="form.personal_profile" placeholder="请输入"></el-input>
                    </el-form-item>
                    <el-form-item label="职务" prop="post">
                        <el-select v-model="form.post" placeholder="请选择职务">
                            <el-option v-for="(item,index) in optType" :key="index" :label="item.p_name" :value="item.p_id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="来源" prop="source">
                        <el-select v-model="form.source" placeholder="请选择来源">
                            <el-option label="市场招聘" value="1"></el-option>
                            <el-option label="网站招聘" value="2"></el-option>
                            <el-option label="员工介绍" value="3"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="头像" class="sfzpic">

                        <el-upload :action="upload()" style="display:inline-block;" :class="{'disabled':idZuploadDisabled}" :file-list="sfzzfilelist" list-type="picture-card" :on-success="idZAvatarSuccess" :before-upload="beforeAvatarUpload" :on-preview="handlePictureCardPreview" :before-remove="sfzZhandleRemove">
                            <i class="el-icon-plus"></i>
                        </el-upload>

                    </el-form-item>
                    <el-form-item label="备注" prop="remark">
                        <el-input type="textarea" v-model="form.remark" placeholder="请输入"></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="cancel('form')" size="mini">取 消</el-button>
                    <el-button type="primary" @click="submit('form')" size="mini">确 定</el-button>
                </span>
            </el-dialog>
            <!-- 放大查看图片 -->
            <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="dialogImageUrl" />
            </el-dialog>
            <div class='list'>
                <el-table :data="list.data" tooltip-effect="dark" style="width: 100%" @row-click="showauthories" highlight-current-row>

                    <el-table-column align="center" prop="u_id" label="员工ID" width="120"></el-table-column>
                    <el-table-column align="center" prop="name" label="部门名称" width="120"></el-table-column>
                    <el-table-column align="center" prop="u_username" label="员工名字" width="120"></el-table-column>
                    <el-table-column align="center" prop="u_account_number" label="账号" width="120"></el-table-column>
                    <el-table-column align="center" prop="u_last_ip" label="最后一次登陆IP" width="120"></el-table-column>
                    <el-table-column align="center" prop="u_last_time" label="最后一次登录时间" width="140"></el-table-column>
                    <el-table-column align="center" :formatter="statusFun" prop="u_status" label="账号状态" width="120"></el-table-column>
                    <el-table-column align="center" prop="created_at" label="创建时间" width="140"></el-table-column>
                    <el-table-column align="center" prop="updated_at" label="修改时间" width="140"></el-table-column>
                    <el-table-column align="center" :formatter="sexFun" prop="sex" label="性别" width="70"></el-table-column>
                    <el-table-column align="center" prop="birthday" label="员工生日" width="100"></el-table-column>
                    <el-table-column align="center" prop="jiguan" label="籍贯" width="120"></el-table-column>
                    <el-table-column align="center" prop="nation" label="民族" width="60"></el-table-column>
                    <el-table-column align="center" prop="college" label="毕业院校" width="120"></el-table-column>
                    <el-table-column align="center" prop="political_face" label="政治面貌" width="60"></el-table-column>
                    <el-table-column align="center" prop="speciality" label="所学专业" width="120"></el-table-column>
                    <el-table-column align="center" :formatter="recordFun" prop="record_type" label="学历" width="60"></el-table-column>
                    <el-table-column align="center" prop="people_num" label="身份证号" width="148"></el-table-column>
                    <el-table-column align="center" prop="phone" label="联系电话" width="120"></el-table-column>
                    <el-table-column align="center" prop="email" label="邮箱" width="150"></el-table-column>
                    <el-table-column align="center" prop="address" label="家庭住址" width="150" show-overflow-tooltip></el-table-column>
                    <el-table-column align="center" prop="bank_num" label="银行卡号" width="155"></el-table-column>
                    <el-table-column align="center" prop="bank_remark" label="银行名称" width="120"></el-table-column>
                    <el-table-column align="center" prop="personal_profile" label="个人简介" width="150" show-overflow-tooltip></el-table-column>
                    <el-table-column align="center" prop="post" label="职务" width="120"></el-table-column>
                    <el-table-column align="center" :formatter="sourceFun" prop="source" label="来源" width="120"></el-table-column>
                    <el-table-column align="center" prop="entry_time" label="入职时间" width="140"></el-table-column>
                    <el-table-column align="center" prop="separation_time" label="离职时间" width="140"></el-table-column>
                    <el-table-column align="center" prop="remark" label="备注" width="150" show-overflow-tooltip></el-table-column>
                    <el-table-column fixed="right" label="操作" width="160">
                    <template slot-scope="scope">
                        <el-button @click.native.prevent="edit(scope.row)" type="text" size="small" :disabled="scope.row.u_type == 2">编辑</el-button>
                        <el-button @click.native.prevent="reset(scope.row)" type="text" size="small">重置密码</el-button>
                        <el-button @click.native.prevent="deltest(scope.row)" type="text" size="small" :disabled="scope.row.u_type == 2">删除</el-button>
                    </template>
                    </el-table-column>
                </el-table>
                <!-- 分页 -->
                <el-pagination :current-page="current" @current-change="handleCurrentChange" :total="list.total" style="margin-top:30px;"></el-pagination>
            </div>
            <!-- authories为该部门或者该员工的权限   permissionId: 被修改的id  typeid:1为部门，2为员工  -->
            <Permission v-if="showPermission" :authories="authories" :permissionId="employeeId" typeid="2" @refreshlistevent="refreshlistievent" />
        </div>
    </div>
</template>
<style>
    .home .view-content{
        width: 87%;
    }
    .el-form-item__label,.el-form-item__content{
        font-size: 12px;
    }
    .el-input{
        padding-right: 5px;
    }
    .el-select-dropdown__item{
        font-size: 12px;
        padding: 0px 10px;
        height: 26px;
        line-height: 26px;
    }
    .el-input,.el-date-editor.el-input{
        width: 145px;
    }

    .el-upload--picture-card{
        display: inline-block;
    }
    .disabled .el-upload--picture-card {
        display: none;
    }
</style>

<script>
    import conf from '../../config/userconf.js'
    import permconfig from "../../config/permconfig.js"
  export default {
    data() {
        var validatePhone = (rule,value,callback) => {    //正则手机号

            var MobileRegex = /^1[3|4|5|7|8][0-9]{9}$/;
            if (!MobileRegex.test(value)) {
                callback(new Error('手机号格式不正确！'))
            } else {
                callback();
            }
        };
        var isCardNo = (rule,value,callback) => {    //正则身份证
                                
            var MobileRegex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            // var MobileRegex = /(^\d{14}[[0-9],0-9xX]$)|(^\d{17}[[0-9],0-9xX]$)/;
            if (!MobileRegex.test(value)) {
                callback(new Error('身份证格式不正确！'))
            } else {
                callback();
            }
        };
        var isEmail = (rule,value,callback) => {    //正则邮箱

            // var MobileRegex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            var MobileRegex = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
            if (!MobileRegex.test(value)) {
                callback(new Error('邮箱格式不正确！'))
            } else {
                callback();
            }
        };
        var validateTel = (rule,value,callback) => {    //正则座机号
            var MobileRegex = /(^(\d{3,4}-)\d{7,8}$)|(^\d{7,8}$)/;
            if (!MobileRegex.test(value)) {
                callback(new Error('电话格式不正确！'))
            } else {
                callback();
            }
        };
        return {
            list:[],
            searchData:{
                    u_id:'',
                    u_d_id:'',
                    u_username:'',
                    u_account_number:'',
            },
            form:{
                    u_d_id:'',
                    u_username:'',
                    // u_account_number:'',
                    u_password:'123456',
                    sex:'',
                    birthday:'',
                    jiguan:'',
                    nation:'',
                    u_status: '',
                    college:'',
                    political_face:'',
                    speciality:'',
                    record_type: '3',
                    people_num:'',
                    phone:'',
                    email:'',
                    address:'',
                    bank_num:'',
                    bank_remark:'',
                    personal_profile:'',
                    post:'',
                    source:'1',
                    remark:'',
            },
            optionName:[],  //部门名称
            userType:[],  //部门员工
            
            typeVal: '',
            rules:{
                u_d_id: [
                    { required: true, message: '请选择所属部门', trigger: 'change' }
                ],
                u_id: [
                    { required: true, message: '请选择所属员工', trigger: 'change' }
                ],
                u_username: [
                    { required: true, message: '请输入用户名称', trigger: 'blur' }
                ],
                u_account_number: [
                    { required: true, message: '请输入用户登陆账号', trigger: 'blur' }
                ],
                u_password: [
                    { required: true, message: '请输入用户登陆密码', trigger: 'blur' },
                ],
                sex: [
                    { required: true, message: '请选择性别', trigger: 'change' }
                ],
                birthday: [
                    { required: true, message: '请选择员工生日', trigger: 'change' }
                ],
                jiguan: [
                    { required: false, message: '请输入籍贯', trigger: 'blur' }
                ],
                nation: [
                    { required: false, message: '请输入民族', trigger: 'blur' }
                ],
                college: [
                    { required: false, message: '请输入毕业院校', trigger: 'blur' }
                ],
                political_face: [
                    { required: false, message: '请输入政治面貌', trigger: 'blur' }
                ],
                speciality: [
                    { required: false, message: '请输入所学专业', trigger: 'blur' }
                ],
                record_type: [
                    { required: true, message: '请选择学历', trigger: 'change' }
                ],
                people_num: [
                    { required: false, message: '请输入身份证号', trigger: 'blur' },
                    {
                        validator:(rule,value,callback)=>{
                            if(value != ""){

                                isCardNo(rule,value,callback)
                                
                            }else{
                                callback();
                            }
                        }, trigger: 'blur'
                    },
                ],
                phone: [
                    { required: true, message: '请输入联系电话', trigger: 'blur' },
                    {
                        validator:(rule,value,callback)=>{
                            if(value != ""){
                                if(value.length < 11 ){
                                    validateTel(rule,value,callback)
                                }else if(value.length >= 11){
                                    validatePhone(rule,value,callback)
                                }
                                
                            }else{
                                callback();
                            }
                        }, trigger: 'blur'
                    },
                ],
                email: [
                    { required: false, type: 'email', message: '请输入正确的电子邮箱', trigger: 'blur' },
                ],
                address: [
                    { required: true, message: '请输入现居住地', trigger: 'blur' }
                ],
                bank_num: [
                    { required: false, message: '请输入银行卡号', trigger: 'blur' }
                ],
                bank_remark: [
                    { required: false, message: '请输入银行名字', trigger: 'blur' }
                ],
                personal_profile: [
                    { required: false, message: '请输入个人简介', trigger: 'blur' }
                ],
                post: [
                    { required: true, message: '请选择职务', trigger: 'change' }
                ],
                source: [
                    { required: true, message: '请选择来源', trigger: 'change' }
                ],
                remark: [
                    { required: false, message: '请输入备注', trigger: 'blur' }
                ],
            },
            multipleSelection: [],
            dialogtitle:'添加员工',
            Timef:true,
            centerDialogVisible:false,
            u_id: '',  //用户id
            current: 1,  //当前页码
            recordType: [
                {name: '小学' , id: '1'},
                {name: '初中' , id: '2'},
                {name: '高中' , id: '3'},
                {name: '中专' , id: '4'},
                {name: '大专' , id: '5'},
                {name: '本科' , id: '6'},
                {name: '硕士' , id: '7'},
                {name: '博士' , id: '8'},
            ],
            showPermission: false,  //是否拥有设置权限   
            authories: '',  //所拥有的权限
            employeeId: '',  //员工id
            optType: [],// 职务下拉框数据
            idZuploadDisabled: false,
            anm_identity_face: {},   //头像  上传服务器
            sfzzfilelist: [],
            dialogVisible: false,  //放大查看图片弹框
            dialogImageUrl: '',  //图片预览路径
        }
    },
    methods: {
        //接收  子组件事件  
        refreshlistievent(){
            //修改权限成功时，应刷新列表数据
            this.getList();
        },
        //职务下拉框
        getoption(data=null){
            conf.duties.getpositionlist(data,(state,res)=>{
                if (state == 'success'&&res.data.code == 0){
                    // console.log(res);
                    this.optType = res.data.data;
                }else if(state == 'success'&&res.data.code != 0){
                    if(res.data.code == 401){
                        this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                    }else if(res.data.code == -404){
                        this.optType = [];
                    }else{
                        this.$message({
                            type: 'info',
                            message: res.data.msg
                        });
                    }
                }
            })
        },
        /* 列表*/
        getList (data=Object()){

            data.page = this.current;
            conf.employee.list(data,(state,res)=>{
                if (state == 'success'&&res.data.code == 0){
                    // console.log(res);
                    this.list = res.data.data;
                }else if(state == 'success'&&res.data.code != 0){
                    if(res.data.code == 401){
                        this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                    }else if(res.data.code == -404){
                        this.list = [];
                    }else{
                        this.$message({
                            type: 'info',
                            message: res.data.msg
                        });
                    }
                }
            })
        },
        /*查询 */
        search () {
            let data  = this.searchData;
            this.getList(data)
        },
        /*取消 */
        cancel (formName) {
            this.centerDialogVisible = false;
            this.$refs[formName].resetFields();
        },
        /*提交 */
        submit (formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.judgeprimise();
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        /*判断提交 */
        judgeprimise (data=Object()) {
            if (this.dialogtitle == '添加员工') {

                if(this.anm_identity_face.anm_identity_face){
                    this.form.avatar = this.anm_identity_face.anm_identity_face;   //头像
                }
                // console.log(this.anm_identity_face.anm_identity_face,this.form);
                conf.employee.add(this.form,(state,res)=>{
                    if (state == 'success'&&res.data.code == 0){
                        this.getList();
                        this.centerDialogVisible = false;
                        this.$message({
                            type: 'success',
                            message: '添加成功!'
                        });
                        this.$alert('您的账号为' +res.data.data, '添加成功', {
                            confirmButtonText: '确定',
                        });
                    }else if(state == 'success'&&res.data.code != 0){
                        if(res.data.code == 401){
                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                        }else{
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        }
                    }
                })
            }else if (this.dialogtitle == '修改员工信息'){
                 var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');
                if(arr.indexOf(permconfig.qx_qita_xiugaiyuangong)  == -1){
                    alert('您没有该功能的权限');
                    return;
                }

                
                data = this.form;
                data.u_id = this.u_id;
                // console.log(this.anm_identity_face.anm_identity_face,this.form,data);
                conf.employee.edit(data,(state,res)=>{
                    if (state == 'success'&&res.data.code == 0){
                        this.getList();
                        this.centerDialogVisible = false;
                        this.$message({
                            type: 'success',
                            message: '修改成功!'
                        });
                    }else if(state == 'success'&&res.data.code != 0){
                        if(res.data.code == 401){
                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                        }else{
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        }
                    }
                })
            }
        },
        /*增 */
        add (formName) {
             var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');
                if(arr.indexOf(permconfig.qx_qita_tianjiayuangong)  == -1){
                    alert('您没有该功能的权限');
                    return;
                }
            this.dialogtitle = '添加员工';
            if(this.optType.length > 0){
                this.form.post = this.optType[0].p_id;
            }
            this.form.u_password = '123456';
            this.centerDialogVisible = true;
        },
        // 删除员工
        deltest (row,data=Object()) {
             var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');
                if(arr.indexOf(permconfig.qx_qita_shanchuyuangong)  == -1){
                    alert('您没有该功能的权限');
                    return;
                }
            // console.log(row);
            this.$confirm('确认删除员工"'+row.u_username+'" ?', '删除员工', {  
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {

                data.u_id = row.u_id;
                conf.employee.del(data,(state,res)=>{
                    if (state == 'success'&&res.data.code == 0){
                        this.getList();
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    }else if(state == 'success'&&res.data.code != 0){
                        if(res.data.code == 401){
                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                        }else{
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        }
                    }
                })

            }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消删除'
                });          
            });
        },
        /**改*/
        edit (val,objs=Object()) {
            // console.log(val);
            this.dialogtitle = '修改员工信息';
            this.form = val;
            this.form.post = val.p_id;
            this.form.sex = this.transformStr(val.sex);
            this.form.record_type = this.transformStr(val.record_type);
            this.form.source = this.transformStr(val.source);
            this.form.u_status = this.transformStr(val.u_status);

            
            if(this.form.avatar){

                this.anm_identity_face.anm_identity_face = this.form.avatar;
                this.sfzzfilelist = [];
                //头像
                objs.url = this.form.avatar;
                this.sfzzfilelist.push(objs);
                //已上传，隐藏继续上传
                this.idZuploadDisabled = true;  
            }

            this.u_id = val.u_id;
            this.centerDialogVisible = true;
            
        },
        //重置密码
        reset(val,data=Object()){
                 var ownerPermission = window.localStorage.getItem('authories');
                var arr = ownerPermission.split(',');
                if(arr.indexOf(permconfig.qx_qita_chongzhimima)  == -1){
                    alert('您没有该功能的权限');
                    return;
                }
            this.$confirm('确认重置员工"'+val.u_username+'"的登陆密码吗 ?', '重置员工密码', {  
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {

                data.u_id = val.u_id;
                conf.employee.resetpassword(data,(state,res)=>{
                    if (state == 'success'&&res.data.code == 0){
                        console.log(res);
                        this.$message({
                            type: 'success',
                            message: res.data.data
                        });
                    }else if(state == 'success'&&res.data.code != 0){
                        if(res.data.code == 401){
                            this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                        }else{
                            this.$message({
                                type: 'info',
                                message: res.data.msg
                            });
                        }
                    }
                })

            }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消重置'
                });          
            });
        },
        // 切换页码
        handleCurrentChange(val) {
            this.current = val;
            this.getList();
        },
        // 上传图片
        upload(){
            let url = conf.baseurl + 'photo';
            return url;
        },
        // 上传文件之前
        beforeAvatarUpload(file) {
            // console.log(file);
            const isJPG = file.type === 'image/jpeg' || 'image/png' || 'image/jpg' || 'image/gif' ||'image/JPEG' || 'image/PNG' || 'image/JPG' || 'image/GIF';
            const isLt2M = file.size / 1024 / 1024 < 2;

            if (!isJPG) {
                this.$message.error('上传头像图片只能是 jpeg、png、jpg、gif 格式!');
            }
            if (!isLt2M) {
                this.$message.error('上传头像图片大小不能超过 2MB!');
            }
            return isJPG && isLt2M;
        },
        idZAvatarSuccess(res, file){
            // console.log(res, file);
            this.faceZUrl = URL.createObjectURL(file.raw);
            this.anm_identity_face.anm_identity_face = res.data.preview_url;
            this.anm_identity_face.add_url = res.data.add_url;

            var objs = {};
            objs.url = res.data.preview_url;
            this.sfzzfilelist.push(objs);
            
            if (this.dialogtitle == '修改员工信息'){
                this.form.avatar = this.anm_identity_face.anm_identity_face;   //头像
            }
            

            //上传成功，隐藏继续上传
            this.idZuploadDisabled = true;  
        },
        handlePictureCardPreview(file) {
            console.log('----预览------',file);
            this.dialogImageUrl = file.url;
            this.dialogVisible = true;
        },
        //删除照片
        sfzZhandleRemove(data=Object()){

            data = {};
            if(this.dialogtitle === '添加员工'){
                data.file_name = this.anm_identity_face.anm_identity_face;
                data.uid = '0';
                conf.employee.delpic(data,(state,res)=>{
                    if(state == 'success'&&res.data.code == 0){
                        this.$message({
                            type: 'success',
                            message: '删除成功'
                        });
                        this.idZuploadDisabled = false;
    
                    }else{
                        this.idZuploadDisabled = true;
                        this.$message({
                            type: 'info',
                            message: res.data.msg
                        });
                    }
                })
            }else if(this.dialogtitle === '修改员工信息'){
                data.file_name = this.anm_identity_face.anm_identity_face;
                data.uid = this.u_id;
                conf.employee.delpic(data,(state,res)=>{
                    if(state == 'success'&&res.data.code == 0){
                        this.$message({
                            type: 'success',
                            message: '删除成功'
                        });
                        this.idZuploadDisabled = false;
                        this.anm_identity_face = {};
                        this.sfzzfilelist = [];

                    }else{
                        this.idZuploadDisabled = true;
                        this.$message({
                            type: 'info',
                            message: res.data.msg
                        });
                    }
                })
            }
            
        },
        //账号状态
        statusFun(row, column, cellValue, index){
            switch (cellValue) {
                case 1:
                    return '正常'
                case 2:
                    return '禁用（审核中）'
                case 3:
                    return '离职'
            }
        },
        //性别
        sexFun(row, column, cellValue, index){
            switch (cellValue) {
                case 1:
                    return '男'
                case 2:
                    return '女'
            }
        },
        //学历
        recordFun(row, column, cellValue, index){
            switch (cellValue) {
                case 1:
                    return '小学'
                case 2:
                    return '初中'
                case 3:
                    return '高中'
                case 4:
                    return '中专'
                case 5:
                    return '大专'
                case 6:
                    return '本科'
                case 7:
                    return '硕士'
                case 8:
                    return '博士'
            }
        },
        //来源
        sourceFun(row, column, cellValue, index){
            switch (cellValue) {
                case 1:
                    return '市场招牌'
                case 2:
                    return '网站招聘'
                case 3:
                    return '员工介绍'
            }
        },
        //单击当前行
        showauthories(row, event, column){
            

            // let authories = window.localStorage.authories.split(",");
            // console.log(row,authories);

            // if(authories.indexOf('151')  != -1){
                this.authories = row.authories;
                this.employeeId = row.u_id;
                //子组件重新渲染
                this.showPermission = false;
                this.$nextTick(function () {
                    this.showPermission = true; 
                });
            // }
        },
        //关闭弹框
        dialogclose(data=Object()){
            this.$refs['form'].resetFields();
        },
        //获取部门
        obtainName(data=Object()){

            conf.department.nameOpt(data,(state,res)=>{
                if (state == 'success'&&res.data.code == 0){
                    this.optionName = res.data.data;
                    // console.log(res); 
                }else if(state == 'success'&&res.data.code != 0){
                    if(res.data.code == 401){
                        this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                    }else if(res.data.code == -404){
                        this.optionName = [];
                    }else{
                        this.$message({
                            type: 'info',
                            message: res.data.msg
                        });
                    }
                }
            }, 'qx_qita_yuangong')
        },
        //获取部门员工
        obtainUser(val,data=Object()){
            this.userType = [];
            this.searchData.u_id = '';
            data.d_id = val;
             var ownerPermission = window.localStorage.getItem('authories');
            var arr = ownerPermission.split(',');
            if(arr.indexOf(permconfig.qx_qita_yuangong_benren)  > -1){
                this.userType = [{
                    "u_id":window.localStorage.getItem('uid'),
                    "u_username":window.localStorage.getItem("uname")
                }]
                return;
            }
            conf.department.userOpt(data,(state,res)=>{
                if (state == 'success'&&res.data.code == 0){
                    this.userType = res.data.data;
                    console.log(this.userType)
                }else if(state == 'success'&&res.data.code != 0){
                    if(res.data.code == 401){
                        this.$router.push({name:'login'});   //登陆态失效，跳转至登录页
                    }else{
                        this.$message({
                            type: 'info',
                            message: res.data.msg
                        });
                    }
                }
            })
        },
    },
    mounted (){
        this.$nextTick(function(){
            this.getList();
            this.obtainName();
            this.getoption();  //职务下拉框
        })
    },
        
  }
</script>